﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using log4net.Config;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using mtgtoolbox.Views;
using mtgtoolbox.ViewModels;

namespace mtgtoolbox
{
  public partial class App : Application
  {
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(App));

    void Application_Startup(object sender, StartupEventArgs e)
    {
      XmlConfigurator.Configure();

      IKernel kernel = new DefaultKernel();
      kernel.Register(  Component.For<MainWindow>()

                       ,Component.For<ICollectionsViewModel>().ImplementedBy<CollectionsViewModel>()
                       ,Component.For<CollectionsView>()
                       ,Component.For<SettingsView>()
                       ,Component.For<AboutView>()
                     );

      kernel.Resolve<MainWindow>().Show();
    }

    void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
      log.Error(e.Exception.Message, e.Exception);

      MessageBox.Show(String.Format("An error has occured {0}",e.Exception.Message));

      e.Handled = true;
      Shutdown();
    }
  }
}
